

namespace Stee.CAP8.MessageBus.Interfaces.Interfaces
{
    using System;
    using System.Collections.Generic;
    using System.Threading.Tasks;
    using Stee.CAP8.MessageBus.Interfaces.Delegates;
    using Stee.CAP8.MessageBus.Interfaces.Models;

    /// <summary>
    /// Admin client interface
    /// </summary>
    public interface IAdmin : IDisposable
    {
        #region Properties

        /// <summary>
        /// Gets the flag indicating that admin client is initialized and ready for configuration
        /// </summary>
        bool IsInitialized { get; }

        /// <summary>
        /// Gets the flag indicating disposed state
        /// </summary>
        bool IsDisposed { get; }

        #endregion Properties


        /// <summary>
        /// Initializes the admin client with specified broker configuration file
        /// </summary>
        /// <param name="brokerConfigurationJSON">JSON broker configuration file path</param>
        /// <param name="brokerErrorHandler">Error handler</param>
        /// <returns>Return TRUE if initialized else FALSE</returns>
        bool Initialize(string brokerConfigurationJSON, HandleBrokerError brokerErrorHandler);

        /// <summary>
        /// Initializes the admin client
        /// </summary>
        /// <param name="adminConfigs">Admin configuration</param>
        /// <param name="brokerErrorHandler">Error handler</param>
        /// <returns>Return TRUE if initialized else FALSE</returns>
        bool Initialize(Dictionary<string, string> adminConfigs, HandleBrokerError brokerErrorHandler);

        /// <summary>
        /// Create new topics in message broker by specified topic configuration file.
        /// An equivalent dead-letter queue topic will be created for each topic
        /// </summary>
        /// <param name="configs">Other topic configurations</param>
        /// <param name="dlqConfigs">Optional: Dead-letter queue topic configuration. If NULL, default configuration is used.</param>
        /// <returns>Return TRUE if created successfully else false</returns>
        Task<bool> CreateNewTopic(IDictionary<string, string> configs, IDictionary<string, string> dlqConfigs = null);

        /// <summary>
        /// Create new topics in message broker by specified topic configuration file.
        /// An equivalent dead-letter queue topic will be created for each topic
        /// </summary>
        /// <param name="topicName">Topic name</param>
        /// <param name="partitionCount">Number of partitions</param>
        /// <param name="repFactor">Topic replication factor</param>
        /// <param name="configs">Other topic configurations</param>
        /// <param name="dlqConfigs">Optional: Dead-letter queue topic configuration. If NULL, default configuration is used.</param>
        /// <returns>Return TRUE if created successfully else false</returns>
        Task<bool> CreateNewTopicAsync(string topicName, int partitionCount, short repFactor,
            IDictionary<string, string> configs, IDictionary<string, string> dlqConfigs = null);

        ///// <summary>
        ///// BUG: Topic deletion only on Windows OS will crash broker, https://issues.apache.org/jira/browse/KAFKA-1194
        ///// Delete topic from message broker
        ///// </summary>
        ///// <param name="topicName">Topic name for deletion</param>
        ///// <returns>Return TRUE if deleted successfully else FALSE</returns>
        //Task<bool> DeleteTopicAsync(string topicName)

        ///// <summary>
        ///// https://github.com/confluentinc/confluent-kafka-dotnet/issues/926, Describing group is not supported yet.
        ///// Reset consumer group offset to latest
        ///// </summary>
        ///// <param name="topicName">Subscription topic</param>
        ///// <param name="consumerGroup">Consumer group ID</param>
        ///// <returns>Return TRUE if the reset is successful else FALSE</returns>
        //Task<bool> ResetOffsetToLatest(TopicName topicName, string consumerGroup)

        /// <summary>
        /// Gets the configuration for specified broker configuration name
        /// </summary>
        /// <param name="brokerID">Broker config ID (broker.id)</param>
        /// <returns>Return a mapping of settings specific to broker configuration</returns>
        Task<IDictionary<string, ConfigurationEntry>> DescribeBrokerConfigAsync(string brokerID);

        /// <summary>
        /// Gets the configurations for specified topic
        /// </summary>
        /// <param name="topicName">Topic name</param>
        /// <returns>Return a mapping of settings specific to topic</returns>
        Task<IDictionary<string, ConfigurationEntry>> DescribeTopicAsync(string topicName);
    }
}
